﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Training.Domain
{
    public enum Fields
    {
        Vat,
        Name,
        Surname,
        Birthdate,
        Salary
    }

    public class Person : Entity
    {
        public string Vat { get; set; }

        public string Name { get; set; }
        public string Surname { get; set; }
        public DateTime Birthdate { get; set; }
        public decimal Salary { get; set; }

        public decimal Age()
        {
            var _age = DateTime.Now - this.Birthdate;
            return (decimal)(_age.TotalDays / 365);
        }

        public string GetValueFieldToEdit(int _ret)
        {
            switch ((Fields)_ret)
            {
                case Fields.Name: return this.Name;
                case Fields.Surname: return this.Surname;
                case Fields.Birthdate: return this.Birthdate.ToString("dd/MM/yyyy");
                case Fields.Salary: return this.Salary.ToString();
                default:
                    throw new ApplicationException();
            }
        }

        public string GetLabelFieldToEdit(int _ret)
        {
            switch ((Fields)_ret)
            {
                case Fields.Name: return "Name";
                case Fields.Surname: return "Surname";
                case Fields.Birthdate: return "BirthDate";
                case Fields.Salary: return "Salary";
                default:
                    throw new ApplicationException();
            }
        }

        public void RefreshValue(int indexEnumFiled, string newValue)
        {
            switch ((Fields)indexEnumFiled)
            {
                case Fields.Name: this.Name = newValue; break;
                case Fields.Surname: this.Surname = newValue; break;
                case Fields.Birthdate: this.Birthdate = DateTime.Parse(newValue); break;
                case Fields.Salary: this.Salary = decimal.Parse(newValue); break;
                default:
                    throw new ApplicationException();
            }
        }

        public void RefreshAllValues(Person person)
        {
            this.Vat = person.Vat;
            this.Name = person.Name;
            this.Salary = person.Salary;
            this.Surname = person.Surname;
            this.Birthdate = person.Birthdate;
        }
    }
}
